def check_readinp(fp):
    import pickle
    import GlobalParam as GP
    gp=GP.iparam

    # Check flow and stage trees
    str1=" - flow=%d, id=%d, nstage=%d\n"
    str2="   [%d] npath=%d\n"
    str3="     + path[%d] next flow=%d,stage=%d,prop=%d\n"
    fp.write(" Flow information\n")
    for i,item1 in enumerate(gp.flow):
        fp.write(str1 % (i,item1.get_id(),item1.get_nstage()))
        for j,item2 in enumerate(item1.stage):
            fp.write(str2 % (j,item2.get_npath()))
            for k in range(item2.get_npath()):
                t=gp.afs1(i,j)
                fp.write(str3 % ( k,t.next_flow[k],\
                                  t.next_stage[k],\
                                  t.path_prop[k] ))
    fp.write("\n")

def check_model(fp):
    import GlobalParam as GP
    gp=GP.iparam

    # # Check generic model
    # str1="  + [%d] filename=%s, id=%d, nmodel=%d\n"
    # fp.write(" Generic model description (%d) \n" % gp.get_ngmodel())
    # for i,item1 in enumerate(gp.generic_model):
    #     fp.write(str1%(i,item1.get_filename(),item1.get_id(),item1.get_nmodel()))
    #     for j in range(item1.get_nmodel()):
    #         str2="   name[%d]: %s" % (j,item1.get_modelname(j))
    #         for k in range(item1.get_ndata(j)):
    #             str2=str2+" %f " % item1.get_data(j,k)
    #         fp.write(str2+"\n")
    # fp.write("\n")

    # Chekc path model
    str1="  + [%d] filename=%s, id=%d, nmodel=%d\n"
    fp.write(" Path model description (%d) \n" % gp.get_npmodel())
    for i,item1 in enumerate(gp.path_model):
        fp.write(str1%(i,item1.get_filename(),item1.get_id(),item1.get_nmodel()))
        for j in range(item1.get_nmodel()):
            str2="   name[%d]: %s" % (j,item1.get_modelname(j))
            for k in range(item1.get_ndata(j)):
                str2=str2+" %f " % item1.get_data(j,k)
            fp.write(str2+"\n")
    fp.write("\n")

    # Check generic groups
    # fp.write(" Generic group description (%d) \n" % gp.get_nggroup())
    # for i,item1 in enumerate(gp.generic_group):
    #     str1="  + [%d] Group id=%d, Group members in index= " % (i, i+1)
    #     str2=""
    #     for j,item2 in enumerate(item1):
    #         str2=str2+("%d "%item2)
    #     fp.write(str1+str2+"\n")
    # fp.write("\n")

    # Check path groups
    fp.write(" Path group description (%d) \n" % gp.get_npgroup())
    for i,item1 in enumerate(gp.path_group):
        str1="  + [%d] Group id=%d, Group members in index= " % (i, i+1)
        str2=""
        for j,item2 in enumerate(item1):
            str2=str2+("%d "%item2)
        fp.write(str1+str2+"\n")
    fp.write("\n")

def check_path(fp):
    import GlobalParam as GP
    gp=GP.iparam
    for i in range(gp.get_nflow()):
        for j in range(gp.flow[i].get_nstage()):
            t=gp.afs1(i,j)
            for k in range(t.get_npath()):
                str1=" (flow,stage,path)=(%d,%d,%d)\n" % (i,j,k)
                pinfo=t.path_info[k]
                # applied path model, generic model
                # str2="  + applied generic model="
                # for item in t.generic_model[k]:
                #     str2=str2+" %d " % item
                # str2=str2+"\n"
                str3="  + applied path model="
                for item in t.path_model[k]:
                    str3=str3+" %d " % item
                str3=str3+"\n"
                fp.write(str1)
                # fp.write(str2)
                fp.write(str3)
                for l in range(pinfo.get_nmodel()):
                    str1="   model name = %s, " %  pinfo.get_modelname(l)
                    for m in range(pinfo.get_ndata(l)):
                        str1=str1+" %4.2e," % pinfo.get_data(l,m)
                    str1=str1+" sum = %4.2e" % pinfo.get_sum(l)
                    fp.write(str1+"\n")
                fp.write("   Total sum = %4.2e\n" % pinfo.get_sum2())
                fp.write("   Probability in sec = %4.2e\n" % gp.get_prob(i,j,k))
                fp.write("\n")
